package defaultPackage;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;

public class PeopleManager 
{
	public ArrayList<Person> people = new ArrayList<Person>();
	protected MainClass main;
	boolean someonesSelected = false;
	
	public PeopleManager(MainClass main)
	{
		this.main=main;
	}
	public void update()
	{
		for(Person i:people)	i.update();
		checkDeath();
	}
	public void draw(Graphics g)
	{
		for(Person i:people)	i.draw(g);
	}
	public Person getPerson(String name)
	{
		Person p = null;
		for(Person i:people)	if(i.name.equals(name))	p=i;
		return p;
	}
	public void addPerson(Person p)
	{
		people.add(p);
	}
	public void checkDeath()
	{
		if (!people.isEmpty())
		{
			for (int i = 0;i<people.size();i++)
			{
				Person p = people.get(i);
				if (p.health == 0)
				{
					Object o = new Object(p.x*10, p.y*10, ObjectType.Corpse, main.grid);
					main.objectmanager.addObject(o);
					o.setDesignation(p.name+"'s Corpse");
					main.amenu.addAnnouncement(p.name+" has died. :(", Color.red);
					people.remove(p);
					i--;
				}
			}
		}
	}
}
